package com.pro.service.imple;

import com.pro.mapper.JsActicleCategroyMapper;
import com.pro.pojo.JsActicleCategroy;
import com.pro.pojo.JsSum;
import com.pro.service.JsActicleCategroyService;
import com.pro.utils.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsActicleCategroyServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2022/1/7 15:10
 * @Author: ZPT
 */
@Service
public class JsActicleCategroyServiceImple implements JsActicleCategroyService {
    @Autowired(required = false)
    private JsActicleCategroyMapper jsActicleCategroyMapper;
    @Autowired
    private RedisCache redisCache;
    @Override
    public List<JsActicleCategroy> getTree() {
        List<JsActicleCategroy> cacheList = redisCache.getCacheList("JsActicleCategroy");
        if (!cacheList.isEmpty()){
            return cacheList;
        }
        //新建选择分类类型
        JsActicleCategroy jsActicleCategroy = new JsActicleCategroy();
        jsActicleCategroy.setActicleCategroyId(0);
        jsActicleCategroy.setArtcleCategroyName("选择分类类型");
        jsActicleCategroy.setArtcleCatefroyParentId(-1);
        List<JsActicleCategroy> tree = jsActicleCategroyMapper.getTree();
        tree.add(jsActicleCategroy);
        redisCache.setCacheList("JsActicleCategroy",tree);
        return tree;
    }

    @Override
    public Boolean addActicleCategroy(JsActicleCategroy jsActicleCategroy) {
        jsActicleCategroy.setCreateDate(new Date());
        Boolean aBoolean = jsActicleCategroyMapper.addActicleCategroy(jsActicleCategroy);
        if (aBoolean){
            redisCache.deleteObject("JsActicleCategroy");
        }
        return aBoolean;
    }

    @Override
    public Boolean updateActicleCategroy(JsActicleCategroy jsActicleCategroy) {
        jsActicleCategroy.setUpdateDate(new Date());
        Boolean aBoolean = jsActicleCategroyMapper.updateActicleCategroy(jsActicleCategroy);
        if (aBoolean){
            redisCache.deleteObject("JsActicleCategroy");
        }
        return aBoolean;
    }

    @Override
    public Boolean deleteActicleCategroy(Integer acticleCategroyId) {
        Boolean aBoolean = jsActicleCategroyMapper.deleteActicleCategroy(acticleCategroyId);
        if (aBoolean){
            redisCache.deleteObject("JsActicleCategroy");
        }
        return aBoolean;
    }
    /**
     *
     * @author ZPT
     * @date 2022/1/19 16:32
     * @content :微圈点赞、分享、点击量
     */
    public List<JsSum> getActicleSum(String field){
        return jsActicleCategroyMapper.getActicleSum(field);
    }
    /**
     *
     * @author ZPT
     * @date 2022/1/19 17:03
     * @content :微圈的收藏量
     */
    public List<JsSum> getCollectArcticleSum(Integer collectionType){
        return jsActicleCategroyMapper.getCollectArcticleSum(collectionType);
    }

}
